package com.yin.lock8;

import java.util.concurrent.TimeUnit;

/**
 * 8lock
 * 关于锁的八个问题
 */
public class Test1 {

    public static void main(String[] args) {
        Phone phone = new Phone();
        new Thread(phone::sendMsg,"A").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(phone::call,"A").start();
    }

}

class Phone {
    public synchronized void sendMsg() {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("sendMsg");
    }

    public synchronized void call() {
        System.out.println("calling");
    }
}
